#ifndef MYVIEW_H
#define MYVIEW_H

#include <QGraphicsProxyWidget>
#include <QGraphicsTextItem>
#include <QGraphicsView>
#include <QGraphicsWidget>
#include <QLabel>
#include <QPushButton>
#include <QSlider>
#include "boxgroup.h"
#include <QMediaPlayer>
class MyView : public QGraphicsView
{
    Q_OBJECT
    static const int INITMSEC = 1000;
public:
    MyView(QWidget *parent = nullptr);
    ~MyView();
    void updateScoreAndLevel(int num);
    bool checkEnd();
    void clearBox();
    void enterGame();
    void startGame();
    void restartGame();
    void endGame();
    void pauseGame();
    void returnGame();
    void exitGame();
    void showMainMenu();
    void hideMainMenu();
    void showPauseWidget();
    void hidePauseWidget();
    void playMedia(QMediaPlayer::MediaStatus status);
    void setBackGroundVolumn(float num);
    void setClearFullLineVolumn(float num);
protected:
    void keyPressEvent(QKeyEvent *event);
private:
    void initView();
    void createBoxGroup();
    void cleanFullLine();

    BoxGroup *curBoxGroup = NULL;
    BoxGroup *nextBoxGroup = NULL;
    QSlider *backgroundVolumnSlider;
    QSlider *clearFullLineVolumnSlider;
    QGraphicsItem *topLine;
    QGraphicsItem *bottomLine;
    QGraphicsItem *leftLine;
    QGraphicsItem *rightLine;
    QGraphicsProxyWidget *pauseBtn;
    QGraphicsProxyWidget *returnBtn;
    QGraphicsProxyWidget *startBtn;
    QGraphicsProxyWidget *enterBtn;
    QGraphicsProxyWidget *restartBtn;
    QGraphicsProxyWidget *returnGameBtn;
    QGraphicsProxyWidget *mainMenuBtn;
    QGraphicsProxyWidget *exitBtn;
    QGraphicsProxyWidget *maskWidget;
    QGraphicsProxyWidget *backgroundVolumnSliderProxy;
    QGraphicsProxyWidget *clearFullLineVolumnSliderProxy;
    QLabel *label;
    QGraphicsTextItem *backgroundVolumnText;
    QGraphicsTextItem *clearFullLineVolumnText;
    QGraphicsTextItem *levelText;
    QGraphicsTextItem *welcomeText;
    QGraphicsTextItem *pauseText;
    QMediaPlayer *backgroundPlayer;
    QAudioOutput *backgroundAudio;
    QMediaPlayer *clearFullLinePlayer;
    QAudioOutput *clearFullLineAudio;
    int level;
    bool gameFlag;
    int gameSpeed = INITMSEC;
    int score;
};
#endif // MYVIEW_H
